function [tval, prob, df] = tu_test(x,y)
%t_test - t test between two populations, assuming UNequal variance
% from Press et al., p. 617
% uses betai function
% Coded P. Manis, 4/27/99

tval = 0;
prob = 0;
df = 0;
if nargin ~= 2, 
    error('Requires two input arguments'); 
end

[m1 n1] = size(x);
[m2 n2] = size(y);
if (m1 ~= 1 & n1 ~= 1) | (m2 ~= 1 & n2 ~= 1)
    error('Requires vector first and second inputs.');
end
 
n1 = length(x);
n2 = length(y);

[mean_x, var_x] = mean_var(x);
[mean_y, var_y] = mean_var(y);
vxy = (var_x/n1) + (var_y/n2);
tval = (mean_x-mean_y)/sqrt(vxy);
df = (vxy*vxy)/(((var_x/n1)^2)/(n1-1)+((var_y/n2)^2)/(n2-1));
prob = beta_i(0.5*df, 0.5, df/(df+tval^2));
return
